package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.module.response.BaseReponse.*;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.dto.SpecificDto;
import com.cheejee.goodscenter.service.SpecificService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author CARRY
 * @Date 2020年11月2日下午6:36:28
 */
@RestController
@RequestMapping("/specific")
@Api(tags = "规格模板")
public class SpecificController {

	@Resource
	private SpecificService service;

	@GetMapping("/")
	@ApiOperation("查询所有规格模板")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getSpecificAll(Integer pageNum, Integer pageSize) {
		return queryOk(service.querySpecific(null, null, pageNum, pageSize));
	}

	@GetMapping("/category")
	@ApiOperation("查询某个分类下的规格模板")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getSpecificByCategory(Integer categoryId, Integer pageNum, Integer pageSize) {
		return queryOk(service.querySpecific(categoryId, null, pageNum, pageSize));
	}

	@PutMapping("/add")
	@ApiOperation("新增规格模板")
	public Object addSpecific(@RequestBody SpecificDto specific) {
		service.addSpecific(specific);

		return addOk(service.querySpecificById(specific.getId()));
	}

	@PutMapping("/change")
	@ApiOperation("修改规格模板")
	public Object changeSpecific(@RequestBody SpecificDto specific) {
		service.changeSpecific(specific);

		return changeOk(service.querySpecificById(specific.getId()));
	}

	@DeleteMapping("/{id}")
	@ApiOperation("删除规格模板")
	public Object deleteSpecific(Long id) {
		service.deleteSpecific(id);

		return deleteOk();
	}
}
